﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.ComponentModel;

namespace BusinessObjects {

  /// <summary>
  /// Child collection
  /// </summary>
  public class Children : ICollection<Child> {

    protected BindingList<Child> childrensList = new BindingList<Child>( );

    /// <summary>
    /// Initializes a new instance of the <see cref="Children"/> class.
    /// </summary>
    public Children( ) { }
    
    /// <summary>
    /// Gets or sets the <see cref="BusinessObjects.Child"/> at the specified index.
    /// </summary>
    public Child this[ int index ] {
      get { return childrensList[ index ]; }
      set { childrensList[ index ] = value; }
    }

    /// <summary>
    /// Copies this instance.
    /// </summary>
    /// <returns></returns>
    public Children Copy( ) {
      Children newList = new Children( );
      foreach ( Child item in childrensList ) {
        newList.Add( item.Copy( ) );
      }
      return newList;
    }

    #region ICollection<Child> Members

    /// <summary>
    /// Adds an item to the <see cref="T:System.Collections.Generic.ICollection`1"></see>.
    /// </summary>
    /// <param name="item">The object to add to the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param>
    /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only.</exception>
    public void Add( Child item ) {
      childrensList.Add( item );
    }

    /// <summary>
    /// Removes all items from the <see cref="T:System.Collections.Generic.ICollection`1"></see>.
    /// </summary>
    /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only. </exception>
    public void Clear( ) {
      childrensList.Clear( );
    }

    /// <summary>
    /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"></see> contains a specific value.
    /// </summary>
    /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param>
    /// <returns>
    /// true if item is found in the <see cref="T:System.Collections.Generic.ICollection`1"></see>; otherwise, false.
    /// </returns>
    public bool Contains( Child item ) {
      return childrensList.Contains( item );
    }

    /// <summary>
    /// Copies to.
    /// </summary>
    /// <param name="array">The array.</param>
    /// <param name="arrayIndex">Index of the array.</param>
    public void CopyTo( Child[ ] array, int arrayIndex ) {
      childrensList.CopyTo( array, arrayIndex );
    }

    /// <summary>
    /// Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"></see>.
    /// </summary>
    /// <returns>The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</returns>
    public int Count {
      get { return childrensList.Count; }
    }

    /// <summary>
    /// Gets a value indicating whether the <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only.
    /// </summary>
    /// <returns>true if the <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only; otherwise, false.</returns>
    public bool IsReadOnly {
      get { return false; }
    }

    /// <summary>
    /// Removes the first occurrence of a specific object from the <see cref="T:System.Collections.Generic.ICollection`1"></see>.
    /// </summary>
    /// <param name="item">The object to remove from the <see cref="T:System.Collections.Generic.ICollection`1"></see>.</param>
    /// <returns>
    /// true if item was successfully removed from the <see cref="T:System.Collections.Generic.ICollection`1"></see>; otherwise, false. This method also returns false if item is not found in the original <see cref="T:System.Collections.Generic.ICollection`1"></see>.
    /// </returns>
    /// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"></see> is read-only.</exception>
    public bool Remove( Child item ) {
      return childrensList.Remove( item ); ;
    }

    #endregion

    #region IEnumerable<Child> Members

    /// <summary>
    /// Returns an enumerator that iterates through the collection.
    /// </summary>
    /// <returns>
    /// A <see cref="T:System.Collections.Generic.IEnumerator`1"></see> that can be used to iterate through the collection.
    /// </returns>
    public IEnumerator<Child> GetEnumerator( ) {
      return childrensList.GetEnumerator( );
    }

    #endregion

    #region IEnumerable Members

    /// <summary>
    /// Returns an enumerator that iterates through a collection.
    /// </summary>
    /// <returns>
    /// An <see cref="T:System.Collections.IEnumerator"/> object that can be used to iterate through the collection.
    /// </returns>
    IEnumerator IEnumerable.GetEnumerator( ) {
      return ( IEnumerator ) GetEnumerator( );
    }

    #endregion



  }
}
